#include "Header.h"
#include "Init.h"
#include "Irp.h"
#include "Clean.h"
#include "Util.h"

NTSTATUS DriverEntry(PDRIVER_OBJECT lpDriverObject, PUNICODE_STRING lpRegPath)
{
    UNREFERENCED_PARAMETER(lpRegPath);

    PDEVICE_OBJECT lpDeviceObject = NULL;
    NTSTATUS ntStatus;
    PLDR_DATA_TABLE_ENTRY lpLdrDataEntry = (PLDR_DATA_TABLE_ENTRY)(lpDriverObject->DriverSection);

    lpDriverObject->DriverUnload = DriverUnload;

    if (lpLdrDataEntry)
        lpLdrDataEntry->Flags |= 0x20;

    do
    {
        ntStatus = InitializeGlobalValues();
        if (STATUS_SUCCESS != ntStatus) break;

        ntStatus = InitControlDeviceObject(lpDriverObject, &lpDeviceObject);
        if (STATUS_SUCCESS != ntStatus) break;
        g_lpDeviceObject = lpDeviceObject;

        for (unsigned int i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; ++i)
        {
            lpDriverObject->MajorFunction[i] = IrpGeneral;
        }
        lpDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = IrpDeviceControl;

        ProtectGlobals.hObProcess = Ob2RegisterCallbacks(L"333159", PsProcessType, ObPreOperationProcessCallback, NULL, NULL);
        ProtectGlobals.hObThread = Ob2RegisterCallbacks(L"333158", PsThreadType, ObPreOperationThreadCallback, NULL, NULL);

    } while (FALSE);

    if (STATUS_SUCCESS != ntStatus)
        FreeControlDeviceObject();

    return ntStatus;
}